package com.ruoyi.business.controller;

import java.util.*;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusYjhzMuchan;
import com.ruoyi.business.service.IBusYjhzMuchanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 亩产数据Controller
 * 
 * @author ruoyi
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/yjhz/muchan")
@Api(tags = "有机旱作-亩产数据")
public class BusYjhzMuchanController extends BaseController
{
    @Autowired
    private IBusYjhzMuchanService busYjhzMuchanService;



    /**
     * 查询亩产数据列表
     */
    @GetMapping("/data")
    @ApiOperation("图表数据")
    public AjaxResult data(BusYjhzMuchan busYjhzMuchan)
    {
        startPage();
        List<BusYjhzMuchan> list = busYjhzMuchanService.selectBusYjhzMuchanList(busYjhzMuchan);
        Map<String,List> map = new HashMap<>();
        List<Long> keyList = new ArrayList<>();
        List<Long> gaoliangList = new ArrayList<>();
        List<Long> guziList = new ArrayList<>();
        List<Long> malingsuList = new ArrayList<>();
        List<Long> handaoList = new ArrayList<>();
        List<Long> yumiList = new ArrayList<>();
        List<Long> dadouList = new ArrayList<>();

        list.forEach(d->{
            keyList.add(d.getYear());
            gaoliangList.add(d.getGaoliang());
            guziList.add(d.getGuzi());
            malingsuList.add(d.getMalingsu());
            handaoList.add(d.getHandao());
            yumiList.add(d.getYumi());
            dadouList.add(d.getDadou());
        });

        Collections.reverse(keyList);
        Collections.reverse(gaoliangList);
        Collections.reverse(malingsuList);
        Collections.reverse(guziList);
        Collections.reverse(handaoList);
        Collections.reverse(yumiList);
        Collections.reverse(dadouList);

        map.put("keyList",keyList);
        map.put("gaoliangList",gaoliangList);
        map.put("malingsuList",malingsuList);
        map.put("guziList",guziList);
        map.put("handaoList",handaoList);
        map.put("dadouList",dadouList);

        return AjaxResult.success(map);

    }


    /**
     * 查询亩产数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BusYjhzMuchan busYjhzMuchan)
    {
        startPage();
        List<BusYjhzMuchan> list = busYjhzMuchanService.selectBusYjhzMuchanList(busYjhzMuchan);
        return getDataTable(list);
    }

    /**
     * 导出亩产数据列表
     */
    @PreAuthorize("@ss.hasPermi('yjhz:muchan:export')")
    @Log(title = "亩产数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusYjhzMuchan busYjhzMuchan)
    {
        List<BusYjhzMuchan> list = busYjhzMuchanService.selectBusYjhzMuchanList(busYjhzMuchan);
        ExcelUtil<BusYjhzMuchan> util = new ExcelUtil<BusYjhzMuchan>(BusYjhzMuchan.class);
        util.exportExcel(response, list, "亩产数据数据");
    }

    /**
     * 获取亩产数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjhz:muchan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busYjhzMuchanService.selectBusYjhzMuchanById(id));
    }

    /**
     * 新增亩产数据
     */
    @PreAuthorize("@ss.hasPermi('yjhz:muchan:add')")
    @Log(title = "亩产数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusYjhzMuchan busYjhzMuchan)
    {
        return toAjax(busYjhzMuchanService.insertBusYjhzMuchan(busYjhzMuchan));
    }

    /**
     * 修改亩产数据
     */
    @PreAuthorize("@ss.hasPermi('yjhz:muchan:edit')")
    @Log(title = "亩产数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusYjhzMuchan busYjhzMuchan)
    {
        return toAjax(busYjhzMuchanService.updateBusYjhzMuchan(busYjhzMuchan));
    }

    /**
     * 删除亩产数据
     */
    @PreAuthorize("@ss.hasPermi('yjhz:muchan:remove')")
    @Log(title = "亩产数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busYjhzMuchanService.deleteBusYjhzMuchanByIds(ids));
    }
}
